package net.xju_13_14.handler;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

public class CglibProxy implements MethodInterceptor {
   private Enhancer enhancer = new Enhancer();

   // 创建代理对象方法
   public Object getProxy(Class clazz) {
       enhancer.setSuperclass(clazz);
       enhancer.setCallback(this);
       return enhancer.create();
   }

    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        System.out.println("方法执行之前");
        Object result = methodProxy.invokeSuper(o, objects);
        System.out.println("方法之后执行");
       return result;
    }
}
